using NJabber.Stream.Elements;
using NUnit.Framework;

namespace NJabber.Client.StanzaFactories
{
    [TestFixture]
    public class PresenceStanaFactoryTest
    {
        [Test]
        public void CreateAvailabilityMessage_IsAvaibleTrue_CreatesCorrectStanza()
        {
            PresenceStanzaFactory factory = new PresenceStanzaFactory();

            PresenceStanza stanza = factory.CreateAvailabilityMessage(true, AvailabilityStatus.Away, "some-description") as PresenceStanza;

            Assert.That(stanza.Type, Is.EqualTo(string.Empty));
            Assert.That(stanza.StatusText, Is.EqualTo("some-description"));
        }

        [Test]
        public void CreateAvailabilityMessage_IsAvaibleFalse_CreatesCorrectStanza()
        {
            PresenceStanzaFactory factory = new PresenceStanzaFactory();

            PresenceStanza stanza = factory.CreateAvailabilityMessage(false, AvailabilityStatus.DoNotDisturb, "some-description") as PresenceStanza;

            Assert.That(stanza.Type, Is.EqualTo("unavailable"));
            Assert.That(stanza.StatusText, Is.EqualTo("some-description"));
        }

        [Test]
        public void CreateAnyMessage_AvailablityStatusAway_CreatesCorrectShowAttribute()
        {
            VerifyAvailablityStatus(AvailabilityStatus.Away, AvailabilityType.Away);
        }

        [Test]
        public void CreateAnyMessage_AvailablityStatusChat_CreatesCorrectShowAttribute()
        {
            VerifyAvailablityStatus(AvailabilityStatus.Chat, AvailabilityType.Chat);
        }

        [Test]
        public void CreateAnyMessage_AvailablityStatusDoNotDisturb_CreatesCorrectShowAttribute()
        {
            VerifyAvailablityStatus(AvailabilityStatus.DoNotDisturb, AvailabilityType.DoNotDisturb);
        }

        [Test]
        public void CreateAnyMessage_AvailablityStatusExtendedAway_CreatesCorrectShowAttribute()
        {
            VerifyAvailablityStatus(AvailabilityStatus.ExtendedAway, AvailabilityType.ExtendedAway);
        }

        [Test]
        public void CreateAnyMessage_NoAvailablityStatus_CreatesCorrectShowAttribute()
        {
            VerifyAvailablityStatus(AvailabilityStatus.None, string.Empty);
        }

        private void VerifyAvailablityStatus(AvailabilityStatus status, string statusString)
        {
            PresenceStanzaFactory factory = new PresenceStanzaFactory();

            PresenceStanza availabilityMessage = (PresenceStanza)factory.CreateAvailabilityMessage(true, status, "");
            PresenceStanza unavailabilityMessage = (PresenceStanza)factory.CreateAvailabilityMessage(false, status, "");

            Assert.That(availabilityMessage.Availability, Is.EqualTo(statusString));
            Assert.That(unavailabilityMessage.Availability, Is.EqualTo(statusString));
        }
    }
}